<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>封装DOM查询的例子</title>
</head>
<body>
<script>
function Elem(id) {
	this.elem = document.getElementById(id)
}

Elem.prototype.html = function(val){
	var elem  =this.elem
	if(val) {
		elem.innerHTML = val
		return this //链式操作
	}else {
		return elem.innerHTML
	}
}

Elem.prototype.on = function(type,fn){
	var elem = this.elem
	elem.addEventListener(type,fn)
}

var div1 = new Elem('div1')
</script>
</body>
</html>